﻿package dt
{
	import dt.exchangeddata.HistoryInfo;
	import dt.exchangeddata.UserLiveBetPoolInfo;
	import dt.exchangeddata.DragonTigerInfo;
	import fl.controls.Button;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.NetStatusEvent;
	import flash.events.SecurityErrorEvent;
	import flash.filters.ConvolutionFilter;
	import flash.media.Video;
	import flash.net.NetConnection;
	import flash.net.NetStream;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import game.AccountInfoPanel;
	import game.BetStatusPanel;
	import game.CountDownPanel;
	import game.events.EventData;
	import game.exchangeddata.HashTable;
	import game.exchangeddata.TableInfo;
	import game.GameRulePanel;
	import game.HotLinePanel;
	import game.interfaces.IGameView;
	import dt.exchangeddata.TableLiveBetPoolInfo;
	import game.constants.ConstData;
	import fl.video.*;
	import dt.BetController;
	import game.GameReportPanel;
	import game.BetPlace;
	import game.VideoControl;
	import game.WelcomeMessagePanel;
	import dt.exchangeddata.BetInfo;	
	import game.GlobalVariables;
	import game.constants.ConstData;
	import common.Utility;
	import fl.controls.CheckBox;

	/**
	 * ...
	 * @author Doan Nguyen Thuy Nha Truc (Bamboo)
	 * @author Nguyen Thi Bich Phuong (Daisy)
	 */
	public class DTGameView extends MovieClip implements IGameView{		
		public var cardPanel:CardPanel;
		public var historyPanel:HistoryPanel;
		public var tableInfoPanel:TableInfoPanel;
		public var tableLiveBetPoolPanel:TableLiveBetPoolPanel;
		public var userLiveBetPoolPanel:UserLiveBetPoolPanel;
		public var dragonTigerPanel:DragonTigerPanel;
		public var gameRulePanel:GameRulePanel;
		public var hotLinePanel:HotLinePanel;
		//public var flvControl:FLVPlayback;
		public var flvControl:Video;
		public var videoControl:VideoControl;
		public var maskVideo:MovieClip;
		public var betController:BetController;
		public var countDownPanel:CountDownPanel;
		public var gameReportPanel:GameReportPanel;
		public var betStatusPanel:BetStatusPanel;
		public var winLosePanel:WinLosePanel;
		public var welcomeMsg:WelcomeMessagePanel;		
		public var channelBottomPanel:dt.ChannelPanel;
		public var channelTopPanel:dt.ChannelPanel;
		public var soundList:SoundList;
		public var volumeGame:VolumeController;
		public var bankerBettingTf:TextField;
		public var playerBettingTf:TextField;

		public var txtBalanceTf:TextField;
		public var balanceTf:TextField;
		public var txtTotalBetTf:TextField;
		public var totalBetTf:TextField;
		
		public var isConfirmBet:Boolean;	
		public var swapRoomPanel:SwapRoomPanel;
		private var isInitBetController:Boolean = false;
		//show swapRoomPanel
		public var txtShowChangeRoomTf:TextField;
		public var btnShowChangeRoom:SimpleButton;		
		//end swapRoomPanel
		
		public var autoBetting:CheckBox;
		
		public var txtShowPoint:TextField;
		public var btnShowPoint:SimpleButton;
		
		public var bgMovie_mc:MovieClip;
	
		public var currency_mc:MovieClip;
		public var txtUserTf:TextField;
		public var userTf:TextField;
		
		public var accountInfoPanel:AccountInfoPanel;
		
		public function DTGameView() {	
			this.betController.gameType = ConstData.GAME_TYPE_DT;
			this.isConfirmBet = false;
			this.betController.addEventListener(EventData.BET_CHANGE, betChangeHandler);				
			
			this.btnShowChangeRoom.addEventListener(MouseEvent.CLICK, hdlShowChangeRoom);
			this.txtShowChangeRoomTf.mouseEnabled = false;
			//this.swapRoomPanel.addEventListener(MouseEvent.ROLL_OUT, swapRoomOutHandler);
			//close change table
			this.txtShowChangeRoomTf.visible = false;
			this.btnShowChangeRoom.visible = false;			
			
			this.channelTopPanel.channel.addEventListener(EventData.UPDATE_VIDEO, hdlTopPanel);
			this.channelBottomPanel.channel.addEventListener(EventData.UPDATE_VIDEO, hdlBottonPanel);	
			this.btnShowPoint.addEventListener(MouseEvent.CLICK, hdlShowPoint);
			init();
			initAutoBetting();
			this.swapRoomPanel.show();
			
			this.txtShowPoint.mouseEnabled = false;
			this.btnShowPoint.mouseEnabled = true;
			
			//visible dragon-tiger game
			this.swapRoomPanel.visible = false;
			this.btnShowPoint.visible = false;
			this.txtShowPoint.visible = false;
		}		
		
		private function hdlShowPoint(e:MouseEvent):void {
			if (GlobalVariables.bacShowPoint) {
				GlobalVariables.bacShowPoint = false;
				this.txtShowPoint.text = GlobalVariables.langInfo.hashTable.lookupString("showNumber");
				
			}else {
				GlobalVariables.bacShowPoint = true;
				this.txtShowPoint.text = GlobalVariables.langInfo.hashTable.lookupString("showPlace");
			}
			var event:EventData;
			event = new EventData(EventData.UPDATE_HISTORY, true);		
			dispatchEvent(event)
		}		
		
		private function hdlBottonPanel(e:EventData):void {
			this.channelTopPanel.channelActived = 	this.channelBottomPanel.channelActived;
			this.channelTopPanel.channelActiving = this.channelBottomPanel.channelActiving;
			this.channelTopPanel.setChannelActiving(this.channelTopPanel.channelActiving, this.channelTopPanel.getYellowColor);
			this.channelTopPanel.setChannelActiving(this.channelTopPanel.channelActived, this.channelTopPanel.getWhiteColor);
		}
		
		private function hdlTopPanel(e:EventData):void {
			this.channelBottomPanel.channelActived = this.channelTopPanel.channelActived;
			this.channelBottomPanel.channelActiving = this.channelTopPanel.channelActiving;
			this.channelBottomPanel.setChannelActiving(this.channelBottomPanel.channelActiving, this.channelBottomPanel.getYellowColor);
			this.channelBottomPanel.setChannelActiving(this.channelBottomPanel.channelActived, this.channelBottomPanel.getWhiteColor);			
		}
		
		private function init():void {
			this.videoControl = new VideoControl();
			this.videoControl.addEventListener(EventData.PLAY_VIDEO, setStream);
			
			this.channelBottomPanel.initChannel(2);
			this.channelBottomPanel.gotoAndStop(2);
			this.soundList.stopSound();			
		}
		
		private function setStream(e:EventData):void {
			this.flvControl.attachNetStream(videoControl.stream_ns);
			videoControl.stream_ns.play(videoControl.streamName);
		}
		
		public function updateVideoPath(flvSource:String):void {			
			if(flvControl!=null) {					
				this.removeChild(flvControl);
				flvControl = null;
			}
			
			this.flvControl = videoControl.updateVideoPath(flvSource, flvControl, maskVideo.x, maskVideo.y, maskVideo.width, maskVideo.height );
			this.addChild(this.flvControl);
			this.flvControl.mask = maskVideo;
			
			var indexflvControl:int = getChildIndex(flvControl);
			var indexTopPanel:int = getChildIndex(channelTopPanel);
			var indexBottomPanel:int = getChildIndex(channelBottomPanel);
			var indexSoundList:int = getChildIndex(soundList);
			var indexVolumeGame:int = getChildIndex(this.volumeGame);
			var indexMin:int = Utility.compare(indexTopPanel, indexBottomPanel, indexSoundList);
			
			if (indexVolumeGame >= indexMin)
			{
				setChildIndex(flvControl, indexMin - 1);
			}
			else {
				setChildIndex(flvControl, indexVolumeGame - 1);
			}			
		}
		
		private function initAutoBetting():void {
			var myformat:TextFormat = new TextFormat();
			myformat.color = 0xFFFFFF;
			myformat.font = "Tahoma";
			myformat.size = 14;

			this.autoBetting.setStyle("textFormat", myformat);
			this.autoBetting.addEventListener(MouseEvent.CLICK, autoBettingHdl);
		}
		
		private function autoBettingHdl(e:Event):void {
			if (e.target.selected) {	
				GlobalVariables.autoAcceptBetting = "1";
			}else{
				GlobalVariables.autoAcceptBetting = "0";
			}			
		}
		
		/**
		 * @author Bamboo
		 * @param	e
		 */
		private function swapRoomOutHandler(e:MouseEvent):void {
			this.swapRoomPanel.hide();			
		}
		
		/**
		 * @author Bamboo
		 * @param	e
		 */
		private function hdlSwapRoomPanel(e:Event):void 
		{
			this.swapRoomPanel.hide();
		}
		
		/**
		 * @author Bamboo
		 * @param	e
		 */
		private function hdlShowChangeRoom(e:Event):void {
			 this.swapRoomPanel.show();
		}
		
		/**
		 * @author Daisy
		 * @param	obj
		 */
		private function updateBettingChip(obj:BetInfo):void {				
			for (var i:int = 0; i < this.betController.betArr.length; i++) {
				BetPlace(this.betController.betArr[i]).setBetValue(obj.arrBettingValue[i]);
				BetPlace(this.betController.betArr[i]).updateChips();
			}
		}
		
		/**
		 * @author Daisy
		 * @param	e
		 */
		private function betChangeHandler(e:EventData):void {
			updateBalance(e.newBalance);			
			this.totalBetTf.text = this.betController.getTotalBetValue().toString();
		}		
				
		/**
		 * @author Bamboo
		 * @param	info
		 */
		public function updateGameHis(historyInfo:*):void {
			this.historyPanel.initBoard(historyInfo.history, historyInfo.historyNum, historyInfo.vodId);
		}

		/**
		 * @author Bamboo
		 * @param	cardPos
		 * @param	cardCode
		 */
		public function updateGameCard(cardPos:String, cardCode:String):void {
			this.cardPanel.showCard(int(cardPos), int(cardCode));
		}
		
		/**
		 * @author Daisy
		 * @param	tableInfo
		 */
		public function updateTableInfo(tableInfo:TableInfo):void {
			this.tableInfoPanel.updateTableInfo(tableInfo);
		}
			
		/**
		 * @author Daisy
		 * @param	minBet
		 * @param	maxBet
		 */
		public function updateTableMinMax(minBet:Number, maxBet:Number):void {
			this.tableInfoPanel.updateTableMinMax(minBet, maxBet);
		}
		
		/**
		 * @author Daisy
		 * @param	strMsg
		 */
		public function updateWelcomeMessage(strMsg:String):void {

			this.welcomeMsg.startWelcome(strMsg);
		}
		
		/**
		 * @author Daisy
		 * @param	liveBetPoolGame
		 */
		public function updateLiveBetPoolGame(liveBetPoolGame:*):void {					
			this.tableLiveBetPoolPanel.updateLiveBetPoolGame(liveBetPoolGame);
		}	
		
		/**
		 * @author Daisy
		 * @param	liveBetPoolUser
		 */
		public function updateLiveBetPoolUserPublic(liveBetPoolUser:*):void {		
			if (this.userLiveBetPoolPanel.isPublic) {						
				this.userLiveBetPoolPanel.updateLiveBetPoolUserPublic(liveBetPoolUser);
			}
		}
		
		/**
		 * @author Daisy
		 */
		public function updateLiveBetPoolUserPrivate():void {			
			if (!this.userLiveBetPoolPanel.isPublic) {				
				this.userLiveBetPoolPanel.updateLiveBetPoolUserPrivate(this.betController.saveBetInfo);
			}
		}
		
		/**
		 * @author Bamboo
		 * @param	playerBankerInfo
		 */
		public function updateGameHisPlayerBanker(dragonTigerInfo:*, type:String, sLoop:String):void {
			if(type == "1")
			{	
				this.dragonTigerPanel.initAskDragonTigerType1(dragonTigerInfo.historyType_1, sLoop);
			}
			else
			{	
				this.dragonTigerPanel.initAskDragonTigerType2(dragonTigerInfo.historyType_2, sLoop);
			}
		}
		/**
		 * @author	Bamboo
		 * @param	sLoop
		 */
		public function updateGameHisAsk(sLoop:String):void
		{	
			this.historyPanel.askBankerPlayer(dragonTigerPanel.curAskClick, sLoop);
		}
		/**
		 * @author	Bamboo
		 * @param	nameTxt
		 */
		public function activeGameRule(nameTxt:String):void {	
			if(this.gameRulePanel.txtRuleTf.text =="")
			{	
				this.gameRulePanel.loadTxt(nameTxt);
			}
			this.gameRulePanel.initText(GlobalVariables.langInfo.hashTable);
			this.gameRulePanel.show();
		}
		/**
		 * @author	bamboo
		 * @param	textTitle
		 * @param	txtPlace
		 * @param	textPhone
		 * @param	textbtnClose
		 */
		public function activeHotLine():void {			
			this.hotLinePanel.show();
		}
		
		/**
		 * @author	Bamboo
		 * @param	flvSource
		 */
		
		/*public function updateVideoPath(flvSource:String):void {
			try{
				if(flvControl!=null)
				{	
					this.removeChild(flvControl);
					flvControl = null;
				}				
				flvControl = new FLVPlayback(); 
				flvControl.x = 3; 
				flvControl.y = 30;      
				flvControl.width = 260;
				flvControl.height = 195;
				flvControl.isLive = true;
				flvControl.source = flvSource;				
				flvControl.getVideoPlayer(flvControl.activeVideoPlayerIndex).smoothing = true;				 
				var filter:ConvolutionFilter = new ConvolutionFilter();
				filter.matrixX = 0;
				filter.matrixY = 0;
				filter.matrix = [-1, 0, -1, 0, 8, 0, -1, 0, -1];
				filter.bias =  0;
				filter.divisor = 4;
				flvControl.filters = [filter];
				addChild(flvControl);
				var otherindex = getChildIndex(flvControl);
				
				setChildIndex(flvControl, 1);
				setChildIndex(bgMovie_mc, 0);
				
		    }catch (e:Error) 
		    {
				trace(e.message);
		    }
		}*/
		
			/*public var connect_nc:NetConnection;
		public var stream_ns:NetStream;
		private var connection:String = "rtmp://113.21.208.1/ipTV";
		private var streamName:String;
	
		public function updateVideoPath(fms:String):void {
			try {
				trace("fms:" + fms);
				var temp:Array = fms.split("@");
				connection = temp[0];
				streamName = temp[1];
				if(flvControl!=null)
				{	
					this.removeChild(flvControl);
					flvControl = null;
				}				
				flvControl = new Video(); 
				flvControl.x = 3; 
				flvControl.y = 30;      
				flvControl.width = 260;
				flvControl.height = 195;
				flvControl.smoothing = true;
				var filter:ConvolutionFilter = new ConvolutionFilter();
				filter.matrixX = 0;
				filter.matrixY = 0;
				filter.matrix = [-1, 0, -1, 0, 8, 0, -1, 0, -1];
				filter.bias =  0;
				filter.divisor = 4;
				flvControl.filters = [filter];
				addChild(flvControl);
			
				connect_nc = new NetConnection();
				connect_nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusNcIdHdl);
				connect_nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHdl);
				connect_nc.connect(connection);
				
				
		    }catch (e:Error) 
		    {
				trace(e.message);
		    }
		}
		
				
		private function netStatusNcIdHdl(e:NetStatusEvent):void {		
			trace("video:"+e.info.code);
			switch(e.info.code) {
				case "NetConnection.Connect.Success":
					stream_ns = new NetStream(connect_nc);
					flvControl.attachNetStream(stream_ns);
					stream_ns.play(streamName);
					break;
				case "NetConnection.Connect.Failed":
					break;
				case "NetConnection.Connect.Rejected":
					break;
				case "NetConnection.Connect.Closed":
						break;
			}
		}	*/
		
		/**
		 * @author Bamboo
		 */
		private function securityErrorHdl(e:SecurityErrorEvent):void {
			trace("SecurityErrorHdl: " + e);
		}	
		
		
		/**
		 * @author Bamboo
		 */
		/*public function stopVideo():void {
			if (flvControl != null) {
				flvControl.stop();
				this.removeChild(flvControl);				
			}
		}*/
		
		public function stopVideo():void {
			/*if (flvControl != null) {
				stream_ns.pause();
				this.removeChild(flvControl);				
			}*/
			this.videoControl.stopVideo();
		}
		/**
		 * @author Bamboo
		 */
		public function showReport():void {			
			this.gameReportPanel.show();
			
			
		}

		/**
		 * @author Daisy
		 * @param	minBet
		 * @param	maxBet
		 * @param	currentBalance
		 * @param	initChipValueArr
		 */
		public function updateChipBetting(minBet:Number, maxBet:Number, currentBalance:Number, initChipValueArr:Array):void {
			//this.balanceTf.text = currentBalance.toString();
			this.updateBalance(currentBalance);
			this.totalBetTf.text = "0";
			if (!this.isInitBetController) {				
				this.isInitBetController = true;    
				this.betController.initBet(minBet, maxBet, currentBalance, initChipValueArr);
			}			
		}		
	
		/**
		 * @author Daisy
		 * @param	currentBettingTime
		 */
		public function countDownBetting(currentBettingTime:int):void {
			this.countDownPanel.startCountDown(currentBettingTime);
			this.betController.unlock();
		}
		
		/**
		 * @author	Bamboo
		 * @param	dateFrom
		 * @param	dateTo
		 */
		public function updateDateReport(dateFrom:String, dateTo:String):void {
			this.gameReportPanel.updateDate(dateFrom, dateTo);
		}
		
		/**
		 * @author	Bamboo
		 * @param	position
		 * @return
		 */
		public function sendDateReportInfo(position:int):String {
			if (position == 1)
			{
				return this.gameReportPanel.txtDateFromTi.text;
			}
			else
			{
				return this.gameReportPanel.txtDateToTi.text;
			}
		}
		/**
		 * @author	Bamboo
		 * @param	info
		 */
		public function updateReport(info:Object):void {
			this.gameReportPanel.updateValueReport(info);
		}
		/**
		 * @author	bamboo
		 * @param	info
		 */
		public function updateValueBetStatus(info:Object):void {
			this.betStatusPanel.updateValueBetStatus(info);
		}
		/**
		 * @author	Bamboo
		 * @param	txtPast
		 * @param	txtOk
		 * @param	txtbetRec
		 * @param	txtDate
		 * @param	txtTime
		 * @param	txtTable
		 * @param	txtGameset
		 * @param	txtBetCode
		 * @param	txtResult
		 * @param	txtAmount
		 * @param	txtWin
		 */
		public function showBetStatus():void {			
			this.betStatusPanel.show();
		}
		
		/**
		 * @author	Bamboo
		 */
		public function initStopGame():void {			
			this.countDownPanel.stopCountDown();
			this.betController.lock();
		
			/**
			 * @author Daisy 
			 * @usage  use for DB_BV to delate chip that countdown = 0
			 */
					
			if (GlobalVariables.autoAcceptBetting == "0") {
				updateBetting();	
				if (this.betController.getTotalBetValue() == 0) {
					showBetSuccess(true, false);					
				} else {					
					showBetSuccess(true, true);
				}
			}
		}
		/**
		 * @author	Bamboo
		 * @param	countDownSecond
		 */
		public function initStartGame(countDownSecond:int):void {			
			countDownBetting(countDownSecond);		
			this.userLiveBetPoolPanel.initLivebetPoolUser();
			this.cardPanel.hideAllCards();
			this.winLosePanel.init();

			//When start game clear all history bet
			//this.betController.clearBet();
			this.betController.clearStartBet();
			this.showBetSuccess(false, false);
			this.totalBetTf.text = "0";
			
			//When start game reset betting value for betInfo & saveBetInfo
			this.betController.saveBetInfo.resetValue();
			this.betController.betInfo.resetValue();			
			
			updateBalanceBetting();
		}
		/**
		 * @author	Bamboo
		 * @param	type
		 */
		public function showWinLose(result:String):void {
			this.winLosePanel.showWinLose(result);
		}

		/**
		 * @author Daisy
		 * @return
		 */
		public function confirmBetting():String {			
			var strConfirmBettingCode:String = "";
			var strConfirmBettingValue:String = "";			
			this.betController.saveBetting();
			if(this.betController.saveBetInfo.getTotalBet() == 0){			
				for (var i:int = 0; i < this.betController.betInfo.arrBettingCode.length; i++) {
					if (this.betController.betInfo.arrBettingValue[i] > 0) {
						strConfirmBettingCode += this.betController.betInfo.arrBettingCode[i] + ",";
						strConfirmBettingValue += this.betController.betInfo.arrBettingValue[i] + ",";
					}
				}			
			} else {
				for (i = 0; i < this.betController.betInfo.arrBettingCode.length; i++) {
					if (this.betController.betInfo.arrBettingValue[i] > 0 
						&& this.betController.betInfo.arrBettingValue[i] > this.betController.saveBetInfo.arrBettingValue[i]) {
						strConfirmBettingCode += this.betController.betInfo.arrBettingCode[i] + ",";
						strConfirmBettingValue += (this.betController.betInfo.arrBettingValue[i] - this.betController.saveBetInfo.arrBettingValue[i]) + ",";
					}
				}			
			}	
			if (strConfirmBettingCode == "")
				return "";
			
			return (strConfirmBettingCode.substr(0, strConfirmBettingCode.length -1) + "@" 
					+ strConfirmBettingValue.substr(0, strConfirmBettingValue.length -1));
		}	
		
		/**
		 * @author Daisy
		 */
		public function saveBettingSuccess():void {
			this.betController.saveBetInfo.copy(this.betController.betInfo);
			updateBalanceBetting();
			
			updateLiveBetPoolUserPrivate();
		}
		
		/**
		 * @author Daisy
		 */
		public function clearBetting(e:EventData):void {
			updateBettingChip(this.betController.saveBetInfo);	
			
			this.updateBalance(e.newBalance);
			//this.balanceTf.text = e.newBalance.toString();
			this.totalBetTf.text = this.betController.betInfo.getTotalBet().toString();				
		}
		
		/**
		 * @author Daisy
		 */
		public function rightBetting():void {			
			var tmp:BetInfo = new BetInfo();
			for (var i:int = 0; i < this.betController.betArr.length; i++) {												
				if (this.betController.hitArr[i].name == GlobalVariables.betPlaceActive) {	
					if ((BetPlace(this.betController.betArr[i]).getBetValue() - this.betController.saveBetInfo.arrBettingValue[i]) >= GlobalVariables.chipActiveAmount) {
						tmp.arrBettingValue[i] = BetPlace(this.betController.betArr[i]).getBetValue() - GlobalVariables.chipActiveAmount;
						
						if(tmp.arrBettingValue[i] > 0) {
							this.betController.tooltip_mc.tooltip_txt.text = tmp.arrBettingValue[i].toString();
						}
						
						this.betController.currentBalance += GlobalVariables.chipActiveAmount;
						this.updateBalance(this.betController.currentBalance);
						this.totalBetTf.text = (this.betController.getTotalBetValue() - GlobalVariables.chipActiveAmount).toString();						
					} else {
						tmp.arrBettingValue[i] = this.betController.saveBetInfo.arrBettingValue[i];
						
						var event:EventData;
						event = new EventData(EventData.SHOW_MS, true);
						event.ms = "changeMsg";
						dispatchEvent(event);
					}
				} else {
					tmp.arrBettingValue[i] = BetPlace(this.betController.betArr[i]).getBetValue();
				}
			}
			updateBettingChip(tmp);
		}
		
		/**
		 * @author Daisy
		 * @param	chipName
		 */
		public function setChipActive(chipName:String):void {			
			for (var i:int = 0; i < this.betController.chipController.chipArr.length; i++) {				
				if (this.betController.chipController.chipArr[i].chipName == chipName) {
					this.betController.chipController.activeChip = this.betController.chipController.chipArr[i];
					this.betController.chipController.chipArr[i].setActive();					
				} else {
					this.betController.chipController.chipArr[i].unActive();
				}
			}			
		}
		
		/**
		 * @author Daisy
		 * @param	e
		 */
		public function rebetBetting(e:EventData):void {			
			var tmp:BetInfo = new BetInfo();
			for (var i:int = 0; i < this.betController.betInfo.arrBettingCode.length; i++) {
				tmp.arrBettingValue[i] = this.betController.saveBetInfo.arrBettingValue[i] + this.betController.preBetInfo.arrBettingValue[i];				
			}
			updateBettingChip(tmp);
			this.updateBalance(e.newBalance);
			//this.balanceTf.text = e.newBalance.toString();
			this.totalBetTf.text = (this.betController.betInfo.getTotalBet() + this.betController.preBetInfo.getTotalBet()).toString();	
		}
		
		/**
		 * @author Daisy
		 * @usage Save betting info to rebet & reset value for save betting info
		 */
		public function updateBetting():void {	
			this.betController.currentBalance = this.betController.currentBalance + this.betController.getTotalBetValue() - this.betController.saveBetInfo.getTotalBet();

			this.updateBalance(this.betController.currentBalance);
		
			this.totalBetTf.text = this.betController.saveBetInfo.getTotalBet().toString();			
			
			//update chip when stop game
			updateBettingChip(this.betController.saveBetInfo);
			
			//save preBetInfo to rebet for next game
			if(this.betController.saveBetInfo.getTotalBet() > 0) {
				this.betController.preBetInfo.copy(this.betController.saveBetInfo);			
			}
		}
		
		/**
		 * @author Daisy
		 * @param	obj
		 */
		public function updateCurrUserBet(obj:Object):void {
			this.betController.updateBet(obj);			
			this.betController.saveBetInfo.resetValue();
			if (this.betController.betInfo.getTotalBet() > 0) {
				this.betController.saveBetInfo.copy(obj);
				//update balance							
				this.totalBetTf.text = this.betController.saveBetInfo.getTotalBet().toString();					
		  	    //update balance user betting
				updateBalanceBetting();
				this.betController.showBetSuccess(true, true);
	        } else {
				this.betController.showBetSuccess(true, false);	
	        }			
			updateLiveBetPoolUserPrivate();			
		}
		/**
		 * @author	Bamboo
		 */
		public function unLockAsk():void {
			this.dragonTigerPanel.unLock();
		}
		/**
		 * @author	Bamboo
		 */
		public function lockAsk():void {
			this.dragonTigerPanel.lock();
		}
		/**
		 * @author	Bamboo
		 * @param	tableNo
		 */
		public function updatePosActiveRoom(tableNo:String) {
			this.swapRoomPanel.setPosActiveRoom(int(tableNo));
		}
		/**
		 * @author	Bamboo
		 * @return
		 */
		public function checkActiveRoom():Boolean {
			return this.swapRoomPanel.checkActiveRoom();
		}
		/**
		 * @author	Bamboo 
		 * @usage	This function had call when contructor
		 */
		public function initGame():void {
			this.cardPanel.hideAllCards();
			this.winLosePanel.init();
			this.countDownPanel.stopCountDown();
		}
        
		/**
		 * @author Daisy
		 * @usage Update Balance User Betting
		 */
		private function updateBalanceBetting() {
			this.bankerBettingTf.text = this.betController.saveBetInfo.arrBettingValue[0].toString();
			this.playerBettingTf.text = this.betController.saveBetInfo.arrBettingValue[1].toString();
		}
		
		/**
		 * @author	Bamboo, Daisy
		 * @param	hashTableInfo
		 */
		public function updateGameTxt(hashTableInfo:HashTable):void {			
            this.txtTotalBetTf.text = hashTableInfo.lookupString("totalBet");			
			this.txtBalanceTf.text = hashTableInfo.lookupString("MNbalance");
			this.txtUserTf.text = hashTableInfo.lookupString("MNwelcome") + ":";
			this.txtShowPoint.text = hashTableInfo.lookupString("showNumber");
			this.swapRoomPanel.initText(hashTableInfo);
			this.dragonTigerPanel.initText(hashTableInfo);
			this.hotLinePanel.initText(hashTableInfo);
			//this.gameRulePanel.initText(hashTableInfo);
			//this.gameReportPanel.initText(hashTableInfo);
			//this.betStatusPanel.initText(hashTableInfo);
			
            this.tableInfoPanel.initText(hashTableInfo);
			this.userLiveBetPoolPanel.initText(hashTableInfo);
			this.tableLiveBetPoolPanel.initText(hashTableInfo);
			this.betController.initText(hashTableInfo);
		}
		
		/**
		 * @author Daisy
		 */
		public function updateBalance(balance:Number):void {		
			this.balanceTf.text = Utility.currency(balance, 2, "");	
			this.betController.currentBalance = balance;
			
			//send value to update balance in game
			/*var e:EventData = new EventData(EventData.SEND_BALANCE_TO_MAIN, true);
			e.newBalance = balance;
			dispatchEvent(e);*/
		}
		
		public function showBetSuccess(isShow:Boolean, isBet:Boolean):void {			
			this.betController.showBetSuccess(isShow, isBet);
		}		
	
		public function updateTablesClose(listRoom:Array):void {
			this.swapRoomPanel.setEnabled(listRoom);			
		}
		public function updateDateClock(tableInfo:TableInfo):void {			
			this.tableInfoPanel.updateDateClock(tableInfo);
		}
		public function initListChannel(data:Array, nameFmsChannel:String):void { 
			this.channelTopPanel.initListChannel(data);
			this.channelBottomPanel.initListChannel(data);
			this.channelTopPanel.setChannelActiving(nameFmsChannel, this.channelTopPanel.getYellowColor);
			this.channelBottomPanel.setChannelActiving(nameFmsChannel, this.channelTopPanel.getYellowColor);
			
			this.channelTopPanel.channelActiving = nameFmsChannel;
			this.channelBottomPanel.channelActiving = nameFmsChannel;
		} 
		
		public function updateUserName(info:String):void {
			this.userTf.text = info;
		}	
		
		public function initCurrency(currency:String):void {			
			switch(currency) {
				case "USD":
					this.currency_mc.gotoAndStop("USD");
					break;
				
				case "SGD":
					this.currency_mc.gotoAndStop("SGD");
					break;
					
				case "HKD":
					this.currency_mc.gotoAndStop("HKD");
					break;
				
				case "TWD":
					this.currency_mc.gotoAndStop("TWD");
					break;
					
				case "CAD":
					this.currency_mc.gotoAndStop("CAD");
					break;			
					
				case "PHP":
					this.currency_mc.gotoAndStop("PHP");
					break;
				
				case "KRW":
					this.currency_mc.gotoAndStop("KRW");
					break;
					
				case "THB":
					this.currency_mc.gotoAndStop("THB");
					break;
				
				case "CNY":
					this.currency_mc.gotoAndStop("CNY");
					break;
					
				case "MYR":
					this.currency_mc.gotoAndStop("MYR");
					break;
				
				case "EUR":
					this.currency_mc.gotoAndStop("EUR");
					break;
					
				case "PTS":
					this.currency_mc.gotoAndStop("USD");
					break;
				
				case "JPY":
					this.currency_mc.gotoAndStop("JPY");
					break;
					
				case "IDR":
					this.currency_mc.gotoAndStop("IDR");
					break;
				
				case "GBP":
					this.currency_mc.gotoAndStop("GBP");
					break;
					
				default:
					this.currency_mc.gotoAndStop("defaultCur");
					break;
			}
		}
		public function initAccountInfo(info:Object):void {
			this.accountInfoPanel.show();
			this.accountInfoPanel.initText(GlobalVariables.langInfo.hashTable);
			this.accountInfoPanel.updateValueAccountInfo(info);
		}
		public function showBetIns(betIns:String, betRate:String):void{};
		public function startIns(coundDownSecond:int, betIns:String):void { };	
		
		public function setBacBetControlStatus(flag:Boolean):void {
			if (flag) {				
				this.betController.lock();
			} else {				
				this.betController.unlock();
			}
		}
		public function setChipNavPos(chipPos:int):void{};
		public function setFutureRoute(result:String, type:String):void{};
	}
}